﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch4
{
    delegate int Transformer(int x);
    class Util
    {
       /// <summary>
       /// 接受一个委托参数并以此为插件方法执行变换操作
       /// </summary>
       /// <param name="values">int数组</param>
       /// <param name="t">委托</param>
        public static void Transform(int[] values, Transformer t)
        {
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = t(values[i]);
            }
        }
    }
    class delegate_example2
    {
        static void _Main(string[] args) 
        {
            int[] values = { 1, 2, 3 };
            Util.Transform(values, Square);
            foreach (int i in values)
            {
                Console.WriteLine(i + " ");//1 4 9
            }
        }
        static int Square(int x) => x * x;
    }
}
